<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css" integrity="sha256-mUZM63G8m73Mcidfrv5E+Y61y7a12O5mW4ezU3bxqW4=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"tallgy.gitee.io","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>
<meta name="description" content="前端性能优化1https:&#x2F;&#x2F;zhuanlan.zhihu.com&#x2F;p&#x2F;115047733    页面加载以及渲染过程优化 CRP优化  关键渲染路径优化 critical rendering path   优化DOM  优化CSSOM  优化 JavaScript  回流重绘的优化  图片懒加载  指定一张图片，src为空也会进行请求，需要设置宽高，不然会出现宽高不匹配的情况   事件委托  利">
<meta property="og:type" content="article">
<meta property="og:title" content="前端性能优化">
<meta property="og:url" content="http://tallgy.gitee.io/2021/11/04/%E6%B5%8F%E8%A7%88%E5%99%A8/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/index.html">
<meta property="og:site_name" content="tallgy&#39;s blog">
<meta property="og:description" content="前端性能优化1https:&#x2F;&#x2F;zhuanlan.zhihu.com&#x2F;p&#x2F;115047733    页面加载以及渲染过程优化 CRP优化  关键渲染路径优化 critical rendering path   优化DOM  优化CSSOM  优化 JavaScript  回流重绘的优化  图片懒加载  指定一张图片，src为空也会进行请求，需要设置宽高，不然会出现宽高不匹配的情况   事件委托  利">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-11-04T12:53:03.000Z">
<meta property="article:modified_time" content="2023-06-25T08:57:29.338Z">
<meta property="article:author" content="tallgy">
<meta property="article:tag" content="随笔">
<meta property="article:tag" content="性能优化">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://tallgy.gitee.io/2021/11/04/%E6%B5%8F%E8%A7%88%E5%99%A8/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://tallgy.gitee.io/2021/11/04/%E6%B5%8F%E8%A7%88%E5%99%A8/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/","path":"2021/11/04/浏览器/前端性能优化/","title":"前端性能优化"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>前端性能优化 | tallgy's blog</title>
  




  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">tallgy's blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96"><span class="nav-number">1.</span> <span class="nav-text">前端性能优化</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E4%BB%A5%E5%8F%8A%E6%B8%B2%E6%9F%93%E8%BF%87%E7%A8%8B%E4%BC%98%E5%8C%96"><span class="nav-number">1.1.</span> <span class="nav-text">页面加载以及渲染过程优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B8%B2%E6%9F%93%E5%AE%8C%E6%88%90%E4%B9%8B%E5%90%8E%E7%9A%84%E9%A1%B5%E9%9D%A2%E4%BA%A4%E4%BA%92%E4%BC%98%E5%8C%96"><span class="nav-number">1.2.</span> <span class="nav-text">渲染完成之后的页面交互优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Vue%E7%9B%B8%E5%85%B3%E6%80%A7%E8%83%BD%E7%9A%84%E4%BC%98%E5%8C%96"><span class="nav-number">1.3.</span> <span class="nav-text">Vue相关性能的优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96-1"><span class="nav-number">1.4.</span> <span class="nav-text">前端性能优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AF%B7%E6%B1%82%E3%80%81%E7%BD%91%E7%BB%9C%E7%9B%B8%E5%85%B3%E7%9A%84%E4%BC%98%E5%8C%96"><span class="nav-number">1.5.</span> <span class="nav-text">请求、网络相关的优化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%AE%80%E5%8D%95%E6%9D%A5%E8%AF%B4%EF%BC%8C%E5%B0%B1%E6%98%AF%E4%BD%BF%E7%94%A8%E5%BC%BA%E7%BC%93%E5%AD%98%E5%92%8C%E5%8D%8F%E5%95%86%E7%BC%93%E5%AD%98%E3%80%82%E5%9C%A8%E5%BC%BA%E7%BC%93%E5%AD%98%E6%97%B6%E9%97%B4%E4%BD%BF%E7%94%A8%E4%BA%86%E5%8D%8F%E5%95%86%E7%BC%93%E5%AD%98%E5%8F%AF%E4%BB%A5%E5%AF%B9%E6%96%87%E4%BB%B6%E8%BF%9B%E8%A1%8Chash%E6%93%8D%E4%BD%9C%E3%80%82"><span class="nav-number">1.5.1.</span> <span class="nav-text">简单来说，就是使用强缓存和协商缓存。在强缓存时间使用了协商缓存可以对文件进行hash操作。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%9B%E8%A1%8C%E5%9B%BE%E7%89%87%E6%87%92%E5%8A%A0%E8%BD%BD%E6%93%8D%E4%BD%9C"><span class="nav-number">1.5.2.</span> <span class="nav-text">进行图片懒加载操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E9%98%B2%E6%8A%96-%E8%8A%82%E6%B5%81"><span class="nav-number">1.5.3.</span> <span class="nav-text">使用防抖&#x2F;节流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BB%84%E4%BB%B6%E6%87%92%E5%8A%A0%E8%BD%BD"><span class="nav-number">1.5.4.</span> <span class="nav-text">组件懒加载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E5%8E%8B%E7%BC%A9"><span class="nav-number">1.5.5.</span> <span class="nav-text">文件压缩</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A1%B5%E9%9D%A2%E6%98%BE%E7%A4%BA%E4%BC%98%E5%8C%96"><span class="nav-number">1.6.</span> <span class="nav-text">页面显示优化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%B9%E4%BA%8E%E9%A1%B5%E9%9D%A2%E4%BD%BF%E7%94%A8%E9%87%8D%E7%BB%98%E5%9B%9E%E6%B5%81"><span class="nav-number">1.6.1.</span> <span class="nav-text">对于页面使用重绘回流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E4%BA%8B%E4%BB%B6%E5%A7%94%E6%89%98"><span class="nav-number">1.6.2.</span> <span class="nav-text">使用事件委托</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%A3%E7%A0%81%E7%BC%96%E5%86%99%E4%BC%98%E5%8C%96"><span class="nav-number">1.7.</span> <span class="nav-text">代码编写优化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#html%EF%BC%8Cjs%EF%BC%8Ccss%E7%9A%84%E4%BD%8D%E7%BD%AE%E5%AF%B9%E4%BA%8EDOM%E6%A0%91%E7%94%9F%E6%88%90%E7%9A%84%E4%BC%98%E5%8C%96%E3%80%82"><span class="nav-number">1.7.1.</span> <span class="nav-text">html，js，css的位置对于DOM树生成的优化。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8-Object-freeze%E6%8F%90%E5%8D%87%E6%80%A7%E8%83%BD"><span class="nav-number">1.7.2.</span> <span class="nav-text">使用 Object.freeze提升性能</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%89%81%E5%B9%B3%E5%8C%96%E6%95%B0%E6%8D%AE"><span class="nav-number">1.7.3.</span> <span class="nav-text">扁平化数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Vue%E7%9A%84%E7%94%9F%E4%BA%A7%E7%8E%AF%E5%A2%83%E5%92%8C%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83"><span class="nav-number">1.7.4.</span> <span class="nav-text">Vue的生产环境和运行环境</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">tallgy</p>
  <div class="site-description" itemprop="description">只是一个知识的搬运工</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">107</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">32</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">74</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://tallgy.gitee.io/2021/11/04/%E6%B5%8F%E8%A7%88%E5%99%A8/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tallgy">
      <meta itemprop="description" content="只是一个知识的搬运工">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tallgy's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          前端性能优化
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-11-04 20:53:03" itemprop="dateCreated datePublished" datetime="2021-11-04T20:53:03+08:00">2021-11-04</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2023-06-25 16:57:29" itemprop="dateModified" datetime="2023-06-25T16:57:29+08:00">2023-06-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E9%9A%8F%E7%AC%94/" itemprop="url" rel="index"><span itemprop="name">随笔</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="前端性能优化"><a href="#前端性能优化" class="headerlink" title="前端性能优化"></a>前端性能优化</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://zhuanlan.zhihu.com/p/115047733</span><br></pre></td></tr></table></figure>



<h2 id="页面加载以及渲染过程优化"><a href="#页面加载以及渲染过程优化" class="headerlink" title="页面加载以及渲染过程优化"></a>页面加载以及渲染过程优化</h2><ul>
<li><p>CRP优化</p>
<ul>
<li>关键渲染路径优化 critical rendering path</li>
</ul>
</li>
<li><p>优化DOM</p>
</li>
<li><p>优化CSSOM</p>
</li>
<li><p>优化 JavaScript</p>
</li>
<li><p>回流重绘的优化</p>
</li>
<li><p>图片懒加载</p>
<ul>
<li>指定一张图片，src为空也会进行请求，需要设置宽高，不然会出现宽高不匹配的情况</li>
</ul>
</li>
<li><p>事件委托</p>
<ul>
<li>利用 JS 事件冒泡机制把元素绑定给父元素</li>
</ul>
</li>
</ul>
<h2 id="渲染完成之后的页面交互优化"><a href="#渲染完成之后的页面交互优化" class="headerlink" title="渲染完成之后的页面交互优化"></a>渲染完成之后的页面交互优化</h2><ul>
<li>防抖节流</li>
</ul>
<h2 id="Vue相关性能的优化"><a href="#Vue相关性能的优化" class="headerlink" title="Vue相关性能的优化"></a>Vue相关性能的优化</h2><ul>
<li>组件懒加载</li>
<li>服务端渲染和预渲染</li>
<li>数据扁平化，合理持久化数据</li>
<li>合理利用 freeze</li>
</ul>
<h2 id="前端性能优化-1"><a href="#前端性能优化-1" class="headerlink" title="前端性能优化"></a>前端性能优化</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">https://zhuanlan.zhihu.com/p/113864878</span><br><span class="line">https://segmentfault.com/a/1190000022205291</span><br></pre></td></tr></table></figure>



<h2 id="请求、网络相关的优化"><a href="#请求、网络相关的优化" class="headerlink" title="请求、网络相关的优化"></a>请求、网络相关的优化</h2><h3 id="简单来说，就是使用强缓存和协商缓存。在强缓存时间使用了协商缓存可以对文件进行hash操作。"><a href="#简单来说，就是使用强缓存和协商缓存。在强缓存时间使用了协商缓存可以对文件进行hash操作。" class="headerlink" title="简单来说，就是使用强缓存和协商缓存。在强缓存时间使用了协商缓存可以对文件进行hash操作。"></a>简单来说，就是使用强缓存和协商缓存。在强缓存时间使用了协商缓存可以对文件进行hash操作。</h3><h3 id="进行图片懒加载操作"><a href="#进行图片懒加载操作" class="headerlink" title="进行图片懒加载操作"></a>进行图片懒加载操作</h3><h3 id="使用防抖-节流"><a href="#使用防抖-节流" class="headerlink" title="使用防抖/节流"></a>使用防抖/节流</h3><h3 id="组件懒加载"><a href="#组件懒加载" class="headerlink" title="组件懒加载"></a>组件懒加载</h3><h3 id="文件压缩"><a href="#文件压缩" class="headerlink" title="文件压缩"></a>文件压缩</h3><h2 id="页面显示优化"><a href="#页面显示优化" class="headerlink" title="页面显示优化"></a>页面显示优化</h2><h3 id="对于页面使用重绘回流"><a href="#对于页面使用重绘回流" class="headerlink" title="对于页面使用重绘回流"></a>对于页面使用重绘回流</h3><h3 id="使用事件委托"><a href="#使用事件委托" class="headerlink" title="使用事件委托"></a>使用事件委托</h3><h2 id="代码编写优化"><a href="#代码编写优化" class="headerlink" title="代码编写优化"></a>代码编写优化</h2><h3 id="html，js，css的位置对于DOM树生成的优化。"><a href="#html，js，css的位置对于DOM树生成的优化。" class="headerlink" title="html，js，css的位置对于DOM树生成的优化。"></a>html，js，css的位置对于DOM树生成的优化。</h3><p>​        对这些位置进行优化。因为js的请求会影响DOM树的编写，js里对css的修改会先生成cssom树，所以在合适的位置编写位置可以进行考虑。</p>
<h3 id="使用-Object-freeze提升性能"><a href="#使用-Object-freeze提升性能" class="headerlink" title="使用 Object.freeze提升性能"></a>使用 Object.freeze提升性能</h3><p>​        Vue的响应式原理，所以可以考虑对一些方法使用冻结来提升性能。</p>
<h3 id="扁平化数据"><a href="#扁平化数据" class="headerlink" title="扁平化数据"></a>扁平化数据</h3><h3 id="Vue的生产环境和运行环境"><a href="#Vue的生产环境和运行环境" class="headerlink" title="Vue的生产环境和运行环境"></a>Vue的生产环境和运行环境</h3>
    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E9%9A%8F%E7%AC%94/" rel="tag"># 随笔</a>
              <a href="/tags/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" rel="tag"># 性能优化</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/10/31/Vue/Vue-methods%E4%BD%BF%E7%94%A8%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0/" rel="prev" title="Vue-methods使用箭头函数">
                  <i class="fa fa-chevron-left"></i> Vue-methods使用箭头函数
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2021/11/05/%E9%9A%8F%E7%AC%94/%E7%BD%91%E7%BB%9C/HTTP%E5%92%8CHTTPS/" rel="next" title="HTTP和HTTPS">
                  HTTP和HTTPS <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">tallgy</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
